<template>
  <div class="CustomColumnDialog">
    <el-dialog class="dialog_alarm" title="报表字段" :visible.sync="dialogVisible" @open="dialogOpen">
      <div class="dialog-body">
        <el-table
          class="dialog-table"
          empty-text=" "
          :data="leftData"
          :show-header="false"
          height="100%"
          highlight-current-row
          @current-change="leftCurrentChange"
        >
          <el-table-column class="table-column" prop="text"></el-table-column>
        </el-table>
        <div class="table-operate">
          <el-button type="text" size="medium" @click="check_all">
            <i class="table-button-icon t-arrow-icon transform90"></i>
          </el-button>
          <el-button type="text" size="medium" @click="checkClick">
            <i class="table-button-icon arrow-icon transform90"></i>
          </el-button>
          <el-button type="text" size="medium" @click="cancelCheckClick">
            <i class="table-button-icon arrow-icon transform270"></i>
          </el-button>
          <el-button type="text" size="medium" @click="cancelCheckAll">
            <i class="table-button-icon t-arrow-icon transform270"></i>
          </el-button>
        </div>
        <el-table
          class="dialog-table"
          empty-text=" "
          :data="rightData"
          :show-header="false"
          height="100%"
          highlight-current-row
          @current-change="rightCurrentChange"
        >
          <el-table-column class="table-column" prop="text"></el-table-column>
        </el-table>
        <div class="table-operate">
          <el-button class="right-button" type="text" size="medium" @click="mvTop">
            <i class="table-button-icon t-arrow-green-icon"></i>
          </el-button>
          <el-button class="right-button" type="text" size="medium" @click="mvTopStep">
            <i class="table-button-icon arrow-green-icon"></i>
          </el-button>
          <el-button class="right-button" type="text" size="medium" @click="mvBottomStep">
            <i class="table-button-icon arrow-green-icon transform180"></i>
          </el-button>
          <el-button class="right-button" type="text" size="medium" @click="mvBottom">
            <i class="table-button-icon t-arrow-green-icon transform180"></i>
          </el-button>
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogHandleConfirm">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import { ReportColumn } from "@/utils/constant";

export default {
  name: "CustomColumnDialog",
  data() {
    return {
      dialogVisible: false,
      leftData: [],
      rightData: [],
      leftCheckItem: {},
      rightCheckItem: {}
    };
  },
  mounted() {
    //
  },
  methods: {
    isShowDia(isVisible) {
      let self = this;
      self.dialogVisible = isVisible;
    },
    dialogOpen() {
      this.leftData = ReportColumn;
      this.rightData = [];
    },
    dialogHandleConfirm() {
      if (this.rightData) {
        localStorage.setItem("saveColumnList", JSON.stringify(this.rightData));
      }
      this.dialogVisible = false;
      this.$emit("change", "click");
    },
    leftCurrentChange(val) {
      this.leftCheckItem = val;
    },
    rightCurrentChange(val) {
      this.rightCheckItem = val;
    },
    check_all() {
      if (this.leftData && this.leftData.length > 0) {
        this.rightData = this.rightData.concat(this.leftData);
        this.leftData = [];
      }
    },
    checkClick() {
      if (this.leftCheckItem) {
        this.rightData.push(this.leftCheckItem);
        this.leftData = this.leftData.filter(
          item => item.value != this.leftCheckItem.value
        );
      } else {
        this.$message({
          message: "请选择"
        });
      }
    },
    cancelCheckClick() {
      if (this.rightCheckItem) {
        this.leftData.push(this.rightCheckItem);
        this.rightData = this.rightData.filter(
          item => item.value != this.rightCheckItem.value
        );
      } else {
        this.$message({
          message: "请选择"
        });
      }
    },
    cancelCheckAll() {
      if (this.rightData && this.rightData.length > 0) {
        this.leftData = this.leftData.concat(this.rightData);
        this.rightData = [];
      }
    },
    mvTop() {
      if (this.rightCheckItem) {
        this.rightData = this.rightData.filter(
          item => item.value != this.rightCheckItem.value
        );
        this.rightData.unshift(this.rightCheckItem);
      } else {
        this.$message({
          message: "请选择"
        });
      }
    },
    mvTopStep() {
      if (this.rightCheckItem) {
        let index = -1;
        this.rightData.forEach((item, item_index) => {
          if (item.value === this.rightCheckItem.value) {
            index = item_index;
          }
        });
        if (index != 0) {
          this.rightData.splice(index, 1);
          this.rightData.splice(index - 1, 0, this.rightCheckItem);
        }
      } else {
        this.$message({
          message: "请选择"
        });
      }
    },
    mvBottomStep() {
      if (this.rightCheckItem) {
        let index = -1;
        this.rightData.forEach((item, item_index) => {
          if (item.value === this.rightCheckItem.value) {
            index = item_index;
          }
        });
        if (index != this.rightCheckItem.length - 1) {
          this.rightData.splice(index, 1);
          this.rightData.splice(index + 1, 0, this.rightCheckItem);
        }
      } else {
        this.$message({
          message: "请选择"
        });
      }
    },
    mvBottom() {
      if (this.rightCheckItem) {
        this.rightData = this.rightData.filter(
          item => item.value != this.rightCheckItem.value
        );
        this.rightData.push(this.rightCheckItem);
      } else {
        this.$message({
          message: "请选择"
        });
      }
    }
  }
};
</script>
<style>
.CustomColumnDialog .el-dialog {
  background-color: rgb(215, 239, 236);
  width: 50%;
  min-width: 480px;
  padding-bottom: 2px;
}
.CustomColumnDialog .dialog_alarm .el-dialog__header {
  padding: 0px 5px;
}
.CustomColumnDialog .dialog_alarm .el-dialog__header .el-dialog__title {
  font-size: 13px;
}
.CustomColumnDialog .dialog_alarm .el-dialog__headerbtn {
  top: 3px;
  right: 10px;
}
.CustomColumnDialog .el-dialog__body {
  border-top: 1px solid #90e8c6;
  border-left: 1px solid #90e8c6;
  border-right: 1px solid #90e8c6;
  background-color: white;
  margin: 0px 5px;
  padding: 0px;
}
.CustomColumnDialog .dialog-body {
  padding: 10px 50px 20px;
  width: 100%;
  height: 400px;
  min-height: 250px;
}
.CustomColumnDialog .dialog-body .dialog-table {
  height: 100%;
  width: 200px;
  float: left;
  border: solid 1px lightgray;
  overflow: auto;
}
.CustomColumnDialog .dialog-table .el-table__body td {
  padding: 0px;
  border-bottom: none;
}
.CustomColumnDialog .dialog-body .table-operate {
  height: 100%;
  width: 100px;
  float: left;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.CustomColumnDialog .table-operate .el-button {
  border: solid 1px gray;
  padding: 5px 25px;
  border-radius: 2px;
  margin-left: 0px;
  background-color: #149eb0;
  margin-bottom: 5px;
  height: 27px;
}
.CustomColumnDialog .table-operate .right-button {
  background-color: white;
}
.CustomColumnDialog .table-operate .table-button-icon {
  width: 14px;
  height: 14px;
  display: block;
  background-size: 100% 100%;
}
.CustomColumnDialog .table-operate .t-arrow-icon {
  background-image: url(../../../../static/resources/images/t_arrow_white.png);
}
.CustomColumnDialog .table-operate .arrow-icon {
  background-image: url(../../../../static/resources/images/arrow_white.png);
}
.CustomColumnDialog .table-operate .t-arrow-green-icon {
  background-image: url(../../../../static/resources/images/t_arrow_green.png);
}
.CustomColumnDialog .table-operate .arrow-green-icon {
  background-image: url(../../../../static/resources/images/arrow_green.png);
}
.CustomColumnDialog .transform90 {
  transform: rotate(90deg);
  -ms-transform: rotate(90deg); /* IE 9 */
  -moz-transform: rotate(90deg); /* Firefox */
  -webkit-transform: rotate(90deg); /* Safari 和 Chrome */
  -o-transform: rotate(90deg); /* Opera */
}
.CustomColumnDialog .transform180 {
  transform: rotate(180deg);
  -ms-transform: rotate(180deg); /* IE 9 */
  -moz-transform: rotate(180deg); /* Firefox */
  -webkit-transform: rotate(180deg); /* Safari 和 Chrome */
  -o-transform: rotate(180deg); /* Opera */
}
.CustomColumnDialog .transform270 {
  transform: rotate(270deg);
  -ms-transform: rotate(270deg); /* IE 9 */
  -moz-transform: rotate(270deg); /* Firefox */
  -webkit-transform: rotate(270deg); /* Safari 和 Chrome */
  -o-transform: rotate(270deg); /* Opera */
}

.CustomColumnDialog .dialog_alarm .el-dialog__footer {
  padding: 0px;
  margin: 5px;
  margin-top: 0px;
  background-color: white;
  border: 1px solid #90e8c6;
}
.CustomColumnDialog .dialog_alarm .el-dialog__footer .el-button {
  padding: 5px 25px;
  margin: 5px 0px 10px;
  font-size: 13px;
}
</style>

